package main

import (
	"encoding/base64"
	"fmt"
	"go_learn/actor"
	"go_learn/app"
	"go_learn/example/math"
	"go_learn/example/test"
	"go_learn/gate"
	"go_learn/network/protobuf"
	"os"
	"os/signal"
)

func main() {
	s1 := test.Test{}
	m := math.Math{}
	app.App.UniqueActor(&m.ConcurrentActor, &m)
	s1Addr, _ := app.App.UniqueActor(&s1.ConcurrentActor, &s1)
	msg1 := actor.RpcMsg{
		Source:  1,
		Session: 1,
		MsgType: actor.Normal,
		Method:  "test1",
	}
	app.App.Send(s1Addr, &msg1)
	uid := base64.StdEncoding.EncodeToString([]byte(`281474976710756001`))
	subid := base64.StdEncoding.EncodeToString([]byte(`1`))
	server := base64.StdEncoding.EncodeToString([]byte(`game`))
	username := uid + "@" + subid + "#" + server
	gate := gate.Gate{TCPAddr: "127.0.0.1:6001", MaxConnNum: 10, PendingWriteNum: 1, Processor: protobuf.NewProcessor()}
	gateAddr, _ := app.App.UniqueActor(&gate.ParallelActor, &gate)
	app.App.Send(gateAddr, &actor.RpcMsg{
		Source:  1,
		Session: 1,
		MsgType: actor.Normal,
		Method:  "login",
		Params:  []interface{}{username, []byte(`abcdefg`)},
	})
	c := make(chan os.Signal)
	//监听所有信号
	signal.Notify(c)
	//阻塞直到有信号传入
	fmt.Println("启动")
	s := <-c
	fmt.Println("退出信号", s)
}
